<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "mkt_friend".
 *
 * @property string $id
 * @property string $user_id
 * @property string $friend_id
 */
class MktFriend extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'mkt_friend';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['user_id', 'friend_id'], 'integer'],
            [['user_id', 'friend_id'], 'unique', 'targetAttribute' => ['user_id', 'friend_id'], 'message' => 'The combination of 我 and 我的好友 has already been taken.']
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'user_id' => '我',
            'friend_id' => '我的好友',
        ];
    }

    /**
     * @inheritdoc
     * @return MktFriendQuery the active query used by this AR class.
     */
    public static function find()
    {
        return new MktFriendQuery(get_called_class());
    }

    public function getUser()
    {
        return $this->hasOne(MktUser::className(), ['id' => 'user_id']);
    }

    public function getFriendUser()
    {
        return $this->hasOne(MktUser::className(), ['id' => 'friend_id']);
    }
    
}
